package com.sgzn.sgpay.service.converter;

import com.sgzn.sgpay.enums.SeqFlagEnum;
import com.sgzn.sgpay.model.request.*;
import com.sgzn.sgpay.persistence.domain.TMerchant;
import com.sgzn.sgpay.persistence.domain.TMerchantPriv;
import com.sgzn.sgpay.persistence.domain.TPrivilege;
import com.sgzn.sgpay.util.SeqUtil;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 权限管理相关请求转换器
 * @author zhongzhongyong
 * @version Id: PrivReqConverter.java, v 0.1 2018/4/17 22:37 zhongzhongyong Exp $$
 */
public class PrivReqConverter {

    /**
     * 权限新增请求转换
     * @param request
     * @return
     */
    public static TPrivilege addReqConvert(SgsPrivAddRequest request){
        TPrivilege tPrivilege = new TPrivilege();
        tPrivilege.setPrivId(SeqUtil.getShortSeq(SeqFlagEnum.PRIVILEGE_ID.getCode()));
        tPrivilege.setPrivName(request.getPrivName());
        tPrivilege.setUrl(request.getUrl());
        tPrivilege.setCreatedAt(new Date());
        tPrivilege.setUpdatedAt(request.getReqTime());
        return tPrivilege;
    }


    /**
     * 商户基础信息更新请求转换
     * @param request
     * @return
     */
    public static TPrivilege updateReqConvert(SgsPrivUpdateRequest request){
        TPrivilege tPrivilege = new TPrivilege();
        tPrivilege.setPrivName(request.getPrivName());
        tPrivilege.setUrl(request.getUrl());
        tPrivilege.setUpdatedAt(request.getReqTime());
        return tPrivilege;
    }

    /**
     * 查询商户账户信息请求转换
     * @return
     */
    public static SgsMerchantQueryBaseRequest queryMchAccReqConvert(SgsMchAccountUpdateRequest request){
        SgsMerchantQueryBaseRequest target = new SgsMerchantQueryBaseRequest();
        target.setInitiationID(request.getInitiationID());
        target.setLoginChannel(request.getLoginChannel());
        target.setReqTime(request.getReqTime());
        target.setMchId(request.getMchId());
        return target;
    }

    /**
     * 获取批量新增商户权限列表
     * @param mchId
     * @param privIdList
     * @return
     */
    public static List<TMerchantPriv> getBatchInsertMchPrivList(String mchId,List<String> privIdList){
        List<TMerchantPriv> resultList = new ArrayList<>();
        for(String privId : privIdList){
            TMerchantPriv vo = new TMerchantPriv();
            vo.setMchId(mchId);
            vo.setPrivId(privId);
            resultList.add(vo);
        }
        return resultList;
    }

    /**
     * 获取批量新增商户权限列表
     * @param mchId
     * @param privIds
     * @return
     */
    public static List<TMerchantPriv> getBatchInsertMchPrivList(String mchId,String[] privIds){
        List<TMerchantPriv> resultList = new ArrayList<>();
        for(String privId : privIds){
            TMerchantPriv vo = new TMerchantPriv();
            vo.setMchId(mchId);
            vo.setPrivId(privId);
            resultList.add(vo);
        }
        return resultList;
    }
}
